package leetcode.medium.isvalid;

import util.annotation.Solved;

/**
 * <h4>
 *     <a href="https://leetcode.cn/problems/check-if-word-is-valid-after-substitutions/">
 *         1003. Check If Word Is Valid After Substitutions [Medium]
 *     </a>
 * </h4>
 * <h4>How to solve this question?</h4>
 * <p>
 *    Keep removing 'abc' from the string until the remaining does not contain 'abc',
 *    then check whether the string is empty.
 * </p>
 */
@Solved
public class Solution {
    public boolean isValid(String s) {
        String str = s;
        int length = str.length();
        while (true) {
            str = str.replace("abc", "");
            if (str.length() == 0 || str.length() == length) {
                break;
            }
            length = str.length();
        }
        return str.length() == 0;
    }
}
